﻿using UnityEngine;

namespace UI.Login.Panel
{
    public class ServerChooseItem : MonoBehaviour
    {
        //按钮本身
        public UIButton btnChooseServer;
        //服务器名字
        public UILabel labName;
        //是否是新服
        public UISprite sprNew;
        //状态
        public UISprite sprState;
        //当前这个按钮 代表的单个服务器信息 之后 用于传给我们的服务器面板
        private Server nowInfo;
        // Start is called before the first frame update
        void Start()
        {
            btnChooseServer.onClick.Add(new EventDelegate(() => {
                //当点击了 这个单个服务器按钮 要做什么

                //记录当前玩家 选择的服务器ID
                LoginMgr.Instance.LoginData.frontServerID = nowInfo.id;

                //隐藏选服面板
                ChooseServerPanel.Instance.HideMe();
                //显示服务器面板
                //更新服务器面板
                ServerPanel.Instance.ShowMe();
            }));
        }

        public void InitInfo(Server info)
        {
            //记录传入的初始化信息
            nowInfo = info;

            //根据传入的单个服务器数据 进行更新

            //显示内容更新
            //名字
            labName.text = info.id + "区  " + info.name;
            //是否显示new 是不是新服
            sprNew.gameObject.SetActive(info.isNew);
            //状态
            sprState.gameObject.SetActive(true);
            switch (info.state)
            {
                case 0:
                    sprState.gameObject.SetActive(false);
                    break;
                case 1:
                    sprState.spriteName = "ui_DL_liuchang_01";
                    break;
                case 2:
                    sprState.spriteName = "ui_DL_fanhua_01";
                    break;
                case 3:
                    sprState.spriteName = "ui_DL_huobao_01";
                    break;
                case 4:
                    sprState.spriteName = "ui_DL_weihu_01";
                    break;
            }
        }
        
    }
}